import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout/index'
Vue.use(VueRouter)

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden:true,
    children:[
      {
        path:'/redirect/:path().*',
        component:()=>import('../views/redirect/index')
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect:'/dashboard',
    children: [
      {
        path: 'dashboard',
        component:()=>import('../views/dashboard/Dashboard'),
        name:'Dashboard',
        meta:{
          title:'首页',
          affix:true,
          icon:'zhiran-iconshouye',
          noCache:true,
          activeMenu:'/dashboard'
        }
      }
    ]
  },
  {
    path:'/data',
    component: Layout,
    redirect: '/data/user-data',
    name:'Data',
    meta:{
      title:'数据',
      icon:'zhiran-icongailan',
    },
    children: [
      {
        path: 'user-data',
        component:()=>import('../views/userdata/UserData'),
        name: 'UserData',
        meta:{
          title: '用户数据'
        }
      },
      {
        path: 'article-data',
        component:()=>import('../views/articledata/ArticleData'),
        name: 'ArticleData',
        meta: {
          title: '帖子数据'
        }
      }
    ]
  },
  {
    path: '/manage',
    component: Layout,
    redirect: '/manage/article-manage',
    name:'Manage',
    meta:{
      title:'管理',
      icon:'zhiran-iconguanli'
    },
    children: [
      {
        path: 'article-manage',
        component:()=>import('../views/manage/articlemanage/ArticleManage'),
        name: 'ArticledManage',
        meta: {
          title: '帖子管理'
        }
      },
      {
        path: 'user-manage',
        component:()=>import('../views/manage/usermanage/UserManage'),
        name: 'UserManage',
        meta: {
          title: '用户管理'
        }
      }
    ]
  }

]

export const asyncRoutes=[
  {
    path:'/permission',
    component:Layout,
    redirect:'permission/user-permission',
    name:'Permission',
    meta:{
      title:'权限管理',
      icon:'zhiran-iconguanli1',
      roles:['super admin']
    },
    children:[
      {
        path:'user-permission',
        component:()=>import('@/views/permission/UserPermission'),
        name: 'UserPermission',
        meta:{
          title:'用户权限',
          roles:['super admin']
        }
      }
    ]
  }
]
const createRouter =()=> new VueRouter({
  mode: 'history',
  scrollBehavior:()=>({y:0}),
  // base: process.env.BASE_URL,
  routes: constantRoutes
})

const router = createRouter()
export function resetRouter(){
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

router.beforeEach(((to, from, next) => {
  next()
}))
export default router
